import 'package:flutter/material.dart';
import 'package:flutter_slidable/flutter_slidable.dart';
import 'package:tender_flutter/constant/app_constant.dart';
import 'package:tender_flutter/constant/resource_path.dart';
import 'package:tender_flutter/constant/theme_colors.dart';
import 'package:tender_flutter/page/home/model/market_entity.dart';
import 'package:tender_flutter/utils/screen_adaper.dart';
import 'package:tender_flutter/utils/utils.dart';

class MyMarketListCell extends StatelessWidget {
  const MyMarketListCell({Key key, this.data, this.onTap, this.deleteCallback})
      : super(key: key);

  final MarketList data;
  final GestureTapCallback onTap;
  final VoidCallback deleteCallback;

  @override
  Widget build(BuildContext context) {
    return _initCell();
  }

  Widget _initCell() {
    return Slidable(
      actionPane: SlidableDrawerActionPane(),
      actionExtentRatio: 0.2,
      secondaryActions: <Widget>[
        // IconSlideAction(
        //   caption: '编辑',
        //   color: ThemeColors.colorType6,
        //   icon: Icons.edit,
        // ),
        IconSlideAction(
          caption: '删除',
          color: ThemeColors.colorType30,
          icon: Icons.delete,
          onTap: deleteCallback,
        ),
      ],
      child: GestureDetector(
        onTap: onTap,
        child: Container(
            color: ThemeColors.colorWhite,
            child: Stack(
              children: <Widget>[
                Column(
                  children: <Widget>[
                    marketStatusView(),
                    Container(
                        margin: EdgeInsets.only(
                            right: ScreenAdapter.width(30),
                            top: ScreenAdapter.height(30)),
                        child: Row(
                            mainAxisAlignment: MainAxisAlignment.spaceBetween,
                            children: [
                              //TODO 此处TypeCode为null应该另行处理
                              Image.asset(
                                  RPath.imgPath +
                                      (data.typeCode ==
                                              AppConstant.MARKET_SUPPLY
                                          ? "img_supply.png"
                                          : "img_demand.png"),
                                  width: ScreenAdapter.width(110),
                                  height: ScreenAdapter.height(40)),
                              RichText(
                                  text: TextSpan(
                                text: data.num ?? "0",
                                style: TextStyle(
                                  fontSize: ScreenAdapter.sp(26),
                                  color: ThemeColors.colorType30,
                                ),
                                children: <TextSpan>[
                                  TextSpan(
                                      text: ' 人已联系',
                                      style: TextStyle(
                                        fontSize: ScreenAdapter.sp(26),
                                        color: ThemeColors.colorType31,
                                      )),
                                ],
                              ))
                            ])),
                    SizedBox(height: ScreenAdapter.height(25)),
                    Container(
                        margin: EdgeInsets.symmetric(
                            horizontal: ScreenAdapter.width(30)),
                        width: double.infinity,
                        child: Text(
                          data.title,
                          maxLines: 2,
                          textAlign: TextAlign.left,
                          style: TextStyle(
                              color: ThemeColors.colorType1,
                              fontSize: ScreenAdapter.sp(32)),
                        )),
                    SizedBox(height: ScreenAdapter.height(30)),
                    Container(
                        margin: EdgeInsets.symmetric(
                            horizontal: ScreenAdapter.width(30)),
                        child: Row(
                          mainAxisAlignment: MainAxisAlignment.spaceBetween,
                          children: <Widget>[
                            Row(
                              children: <Widget>[
                                Container(
                                  margin: EdgeInsets.only(
                                      right: ScreenAdapter.width(20)),
                                  padding: EdgeInsets.only(
                                      left: ScreenAdapter.width(20),
                                      right: ScreenAdapter.width(20),
                                      top: ScreenAdapter.width(10),
                                      bottom: ScreenAdapter.width(10)),
                                  child: Text(data.area ?? "-",
                                      style: TextStyle(
                                          color: ThemeColors.colorType40,
                                          fontSize: ScreenAdapter.sp(24))),
                                  decoration: BoxDecoration(
                                      color: ThemeColors.colorType20,
                                      borderRadius:
                                          new BorderRadius.circular(6)),
                                ),
                                Container(
                                  padding: EdgeInsets.only(
                                      left: ScreenAdapter.width(20),
                                      right: ScreenAdapter.width(20),
                                      top: ScreenAdapter.width(10),
                                      bottom: ScreenAdapter.width(10)),
                                  child: Text("${data.money ?? "0"}元",
                                      style: TextStyle(
                                          color: ThemeColors.colorType42,
                                          fontSize: ScreenAdapter.sp(24))),
                                  decoration: BoxDecoration(
                                      color: ThemeColors.colorType41,
                                      borderRadius:
                                          new BorderRadius.circular(6)),
                                ),
                              ],
                            ),
                            Text(data.createDate ?? "-",
                                style: TextStyle(
                                    color: ThemeColors.colorType1,
                                    fontSize: ScreenAdapter.sp(24))),
                          ],
                        )),
                    SizedBox(height: ScreenAdapter.height(20)),
                  ],
                ),
                // Container(
                //     alignment: Alignment.topRight,
                //     child: Image.asset(
                //       RPath.imgPath + "icon_top.png",
                //       width: ScreenAdapter.width(80),
                //       height: ScreenAdapter.width(80),
                //     ))
              ],
            )),
      ),
    );
  }

  Widget marketStatusView() {
    String text = "";
    String detailText = "";
    Color textColor = ThemeColors.colorType1;
    if (data.status == 2) {
      text = "审核中";
      textColor = ThemeColors.colorType16;
    } else if (data.status == 5) {
      text = "已拒绝";
      detailText = " | ${data.remark}";
      textColor = ThemeColors.colorType17;
    }
    return Offstage(
        offstage: isEmpty(text) ? true : false,
        child: Container(
            margin: EdgeInsets.only(top: ScreenAdapter.height(20)),
            alignment: Alignment.centerLeft,
            child: RichText(
                text: TextSpan(
              text: text,
              style:
                  TextStyle(fontSize: ScreenAdapter.sp(32), color: textColor),
              children: <TextSpan>[
                TextSpan(
                    text: detailText,
                    style: TextStyle(
                      fontSize: ScreenAdapter.sp(32),
                      color: textColor,
                    )),
              ],
            ))));

    //   Text(
    //   "审核中",
    //   style: TextStyle(
    //       color: ThemeColors.colorType1,
    //       fontSize: ScreenAdapter.sp(32)),
    // );
  }
}
